define([],function (){
    const MuAvatarUpload = {
        template: `<el-upload
    class="avatar-uploader"
    :action="uploadurl"
    :show-file-list="false"
    :on-success="success"
  >
    <img v-if="imageUrl" :src="imageUrl" class="avatar" />
    <el-icon v-else class="avatar-uploader-icon" size="20"><Plus /></el-icon>
    <el-button type="primary" v-if="hasXz" size="small" style="margin-left: 10px" @click.stop="xzImg">选择图片</el-button>
  </el-upload>`,
        data(){
            return {
                imageUrl: this.modelValue,
                uploadurl:Config.upload.uploadurl
            }
        },
        props:{
            modelValue:{
                type:String,
                default:''
            },
            hasXz:{
                type:Boolean,
                default:true
            }
        },
        emits:['update:modelValue'],
        methods: {
            success(response, uploadFile, uploadFiles){
                console.log(response)
                if(response.code == 1){
                    this.imageUrl = response.data.url
                    this.$emit('update:modelValue',response.data.url)
                }
            },
            xzImg(){
                let url = Config.upload.show_file_url+'?type=image/*&multiple=0'
                window.callback = (data)=>{
                    this.imageUrl = data;
                    this.$emit('update:modelValue',data)
                    // console.log(data,'data')
                }
                layer.open({
                    type: 2,
                    title: '选择图片',
                    area: ['100%', '100%'],
                    content: url,
                    end:function (){
                        console.log('完成')
                    }
                })
            }
        }
    }
    return MuAvatarUpload
})